package com.kotlin.tsw.usercenter.ui.activity

import android.os.Bundle
import android.view.View
import com.kotlin.tsw.baselibrary.ext.enable
import com.kotlin.tsw.baselibrary.ui.activity.BaseMVPActivity
import com.kotlin.tsw.usercenter.R
import com.kotlin.tsw.usercenter.injection.component.DaggerUserComponent
import com.kotlin.tsw.usercenter.injection.module.UserModule
import com.kotlin.tsw.usercenter.presenter.ResetPwdPersenter
import com.kotlin.tsw.usercenter.presenter.view.ResetPwdView
import kotlinx.android.synthetic.main.activity_reset_pwd.*
import org.jetbrains.anko.clearTop
import org.jetbrains.anko.intentFor
import org.jetbrains.anko.singleTop
import org.jetbrains.anko.toast

class ResetPwdActivity : BaseMVPActivity<ResetPwdPersenter>(), ResetPwdView, View.OnClickListener {

    var mobile: String = ""
    override fun injectComponent() {
        DaggerUserComponent.builder().activityComponent(activityComponent).userModule(UserModule()).build().inject(this)
        mPresenter.mView = this
    }

    override fun onResetPwdResult(result: String) {
        toast(result)
        startActivity(intentFor<LoginActivity>().singleTop().clearTop())
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_reset_pwd)
        mobile=intent.getStringExtra("Mobile")
        initView()
    }

    private fun initView() {
        mConfirmBtn.enable(mPwdEt, { isButtonEnable() })
        mConfirmBtn.enable(mPwdConfirmEt, { isButtonEnable() })
        mConfirmBtn.setOnClickListener(this)

    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.mConfirmBtn -> {
//                mPresenter.resetPwd(mobile, mPwdEt.text.toString().trim())
                startActivity(intentFor<LoginActivity>().singleTop().clearTop())
            }
        }
    }

    fun isButtonEnable(): Boolean {
        return !mPwdEt.text.isNullOrEmpty() &&
                !mPwdConfirmEt.text.isNullOrEmpty()
    }
}
